package com.example.graduation.controller;


import com.example.graduation.entity.Notice;
import com.example.graduation.form.IdForm;
import com.example.graduation.service.impl.NoticeServiceImpl;
import com.example.graduation.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xyc
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    private NoticeServiceImpl noticeService;


    /**
     * @api {POST} /notice/findSend 查找本人发送的消息
     * @apiVersion 1.0.0
     * @apiGroup NoticeController
     * @apiName findSend
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=BAYCi3
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findSend")
    @ResponseBody
    public R findSend(@RequestHeader String token) {
        List<Notice> send = noticeService.findSend(token);
        return R.ok().put("send", send);
    }


    /**
     * @api {POST} /notice/findaccept 查找本人接受的消息
     * @apiVersion 1.0.0
     * @apiGroup NoticeController
     * @apiName findaccept
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=Jjp5uxP0Zl
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findaccept")
    @ResponseBody
    public R findaccept(@RequestHeader String token) {
        List<Notice> send = noticeService.findaccept(token);
        return R.ok().put("send", send);
    }


    /**
     * @api {POST} /notice/checkNotice 查看发送消息本体
     * @apiVersion 1.0.0
     * @apiGroup NoticeController
     * @apiName checkNotice
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=qqZ
     * @apiParam (请求体) {Number} shopId
     * @apiParamExample 请求体示例
     * {"shopId":396}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/checkNotices")
    @ResponseBody
    public R checkNotices(@RequestBody IdForm form) {
        Notice notice = noticeService.checkNotices(form.getShopId());
        return R.ok().put("notice", notice);
    }


    /**
     * @api {POST} /notice/checkNoticea 查看接受消息本体
     * @apiVersion 1.0.0
     * @apiGroup NoticeController
     * @apiName checkNoticea
     * @apiParam (请求体) {Number} shopId
     * @apiParamExample 请求体示例
     * {"shopId":4485}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/checkNoticea")
    @ResponseBody
    public R checkNoticea(@RequestBody IdForm form) {
        Notice notice = noticeService.checkNoticea(form.getShopId());
        return R.ok().put("notice", notice);
    }


    /**
     * @api {POST} /notice/findaccept1 查询管理员接收的消息
     * @apiVersion 1.0.0
     * @apiGroup NoticeController
     * @apiName findaccept1
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=qPOUA79
     * @apiParam (请求体) {Number} shopId
     * @apiParamExample 请求体示例
     * {"shopId":6044}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findaccept1")
    @ResponseBody
    public R findaccept1(@RequestBody IdForm form, @RequestHeader String token) {
        List<Notice> notices = noticeService.findaccept1(token, form.getShopId());
        return R.ok().put("notices", notices);
    }


    /**
     * @api {POST} /notice/findByid 根据id查询
     * @apiVersion 1.0.0
     * @apiGroup NoticeController
     * @apiName findByid
     * @apiParam (请求体) {Number} shopId
     * @apiParamExample 请求体示例
     * {"shopId":3543}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/findByid")
    @ResponseBody
    public R findByid(@RequestBody IdForm form) {
        Notice notice = noticeService.findByid(form.getShopId());
        return R.ok().put("notice", notice);
    }


    /**
     * @api {POST} /notice/ok 同意申请
     * @apiVersion 1.0.0
     * @apiGroup NoticeController
     * @apiName ok
     * @apiParam (请求体) {Number} shopId
     * @apiParamExample 请求体示例
     * {"shopId":7839}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/ok")
    @ResponseBody
    public R ok(@RequestBody IdForm form) {
        Notice notice = noticeService.ok(form.getShopId());
        return R.ok().put("notice", notice);
    }

}

